package cn.minimelon.api.controller.system;


import cn.hutool.core.util.StrUtil;
import cn.minimelon.api.controller.common.BaseController;
import cn.minimelon.api.domain.common.AjaxResult;
import cn.minimelon.api.domain.model.RegisterBody;
import cn.minimelon.api.service.common.ISysConfigService;
import cn.minimelon.api.service.system.ISysRegisterService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@Controller
public class SysRegisterController extends BaseController {
    @Inject
    ISysRegisterService registerService;

    @Inject
    ISysConfigService configService;

    @Post
    @Mapping("/register")
    public AjaxResult register(RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StrUtil.isEmpty(msg) ? success() : error(msg);
    }
}
